package com.szgr.baoyin.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.szgr.baoyin.R;
import com.szgr.baoyin.activity.BigPictureActivity;
import com.szgr.baoyin.model.HomePageImage;
import com.szgr.baoyin.utils.MyTool;

import java.util.List;

/**
 * 首页轮播图片的adapter
 * Created by Jimbo on 2015/9/17.
 */
public class FirstInstallPagerAdapter extends PagerAdapter {
    private Context mContext;
    private int[] arr;
    public FirstInstallPagerAdapter(Context context,int[] arr){
        mContext = context;
        this.arr = arr;
    }

    @Override
    public int getCount() {
        return arr.length;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        ImageView ret = new ImageView(mContext);
        ret.setTag(position);
        ret.setScaleType(ImageView.ScaleType.CENTER_CROP);
//        WindowManager manager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
//        ret.setMaxWidth(MyTool.getScreenWidth(manager));
//        int height = MyTool.getScreenHeight(manager);
//        ret.setMaxHeight((height-48-48) * 3 / 13);
//        ret.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
//        ret.setAdjustViewBounds(true);


//        ret.setImageResource(imageIds.get(position));
//        MyTool.showPicture(mContext,ret, getUrls().get(position % getUrls().size()).getImage());
        ret.setImageResource(arr[position]);

        container.addView(ret);

        return ret;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        if (object instanceof ImageView) {
            container.removeView((View) object);
        }
    }

}
